home *** CD-ROM | disk | FTP | other *** search
Lisp/Scheme | 1988-04-07 | 2.1 KB | 61 lines | [TEXT/ttxt] |
- ;; Larry Mulcahy 1988
- ;; primitive string functions (the ones required by SEQUENCE)
-
- (provide 'string-primitive)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; string:position
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; return the 0-origin position of the first occurrence of the
- ; character c in the string s.
- ; If not found, return nil.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun string:position (c s)
- (dotimes (i (length s) nil)
- (if (equal c (char s i))
- (return i))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; string:position-if
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun string:position-if (test s)
- (dotimes (i (length s) nil)
- (if (funcall test (char s i)) (return i))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; string:position-if-not
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun string:position-if-not (test s)
- (dotimes (i (length s) nil)
- (if (not (funcall test (char s i))) (return i))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; string:substitute
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun string:substitute (new old string &key (test #'eql))
- (let ((big (length string)))
- (if (> big 0)
- (dotimes (i big string)
- (let ((c (char string i)))
- (if (funcall test c old)
- (return
- (strcat (subseq string 0 i)
- (char->string new)
- (string:substitute new
- old
- (subseq string (1+ i))))))))
- string)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; char->string
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; With the change to version 2.0 this became a trivial function
-
- (defun char->string (c) (string c))
-
-
-